package com.study.fileCheck;

import java.io.BufferedReader;

public abstract class FileReader implements AutoCloseable {

    protected BufferedReader reader;

    protected FileReader() {
    }

    public FileReader(BufferedReader reader) {
        if (reader == null) {
            throw new NullPointerException("BufferedReader \"reader\" is null");
        }
        this.reader = reader;
    }

    /**
     * 设置文件字段间分隔符
     *
     * @param symbol 分隔符
     */
    public abstract void setSymbol(String symbol);

    /**
     * 读取一行文件数据，并返回按指定分隔符切分后的字符出数组
     *
     * @return 一行切分后的数据
     * @throws Exception
     */
    public abstract String[] read() throws Exception;

    @Override
    public void close() throws Exception {
        if (reader == null)
            return;
        try {
            reader.close();
            reader = null;
        } catch (Exception e) {
        }
    }
}

